# 1）
# class Employee:
#     def __init__(self, name, salary):
#         self.name = name
#         self.salary = salary
#
#     def calculate_pay(self):
#         return self.salary

# # 任务1：创建Manager类继承Employee
# # 添加bonus属性
# # 重写calculate_pay()方法计算总薪资(salary + bonus)
#
# # 任务2：创建HourlyEmployee类继承Employee
# # 添加hours_worked属性
# # 重写calculate_pay()方法计算时薪(salary/hours_worked)
class Employee:
    def __init__(self, name, salary):
        self.name = name
        self.salary = salary

    def calculate_pay(self):
        return self.salary

class Manager(Employee):
    def __init__(self, name, salary,bonus):
        super().__init__(name,salary)
        self.bonus = bonus

    def calculate_pay(self):
        return super().calculate_pay() +self.bonus

class HourlyEmployee(Employee):
    def __init__(self, name, salary,hours_worked):
        super().__init__(name,salary)
        self.hours_worked = hours_worked

    def calculate_pay(self):
        return super().calculate_pay()/self.hours_worked

a=Employee('小黄',9000)
print(a.calculate_pay())

b=Manager('李经理', 15000, 5000)
print(b.calculate_pay())

c=HourlyEmployee('张工', 10000, 160)
print(c.calculate_pay())

# 2）设计一个简单的游戏系统，包含不同类型的角色（战士、法师、射手），每个角色都有attack()方法，但实现方式不同。请用代码展示如何利用多态来实现这个系统。
class Game:
    def __init__(self,name):
        self.name = name
    def attack(self):
        print("攻击模式")

class Warrior(Game):
    def __init__(self,name,type):
        super().__init__(name)
        self.type = type

class Mage(Game):
    def __init__(self,name,type):
        super().__init__(name)
        self.type = type

class Archer(Game):
    def __init__(self,name,type):
        super().__init__(name)
        self.type = type

def method(game:Game): # int str list  shape1代表一个对象
    print(game.name,game.type)

a = Game("游戏")
a.attack()
b = Warrior("战士","近战物理攻击")
c = Mage("法师","远程魔法攻击")
d = Archer("射手","远程物理攻击")
method(b)
method(c)
method(d)



